#include <iostream>
using namespace std;


void fun(int a)
{
	cout << a << endl;
}

//4种类型转换方式
void cast_type()
{

	float a = 2.01;
	cout << "a = " << a << endl;
	//1、static_cast 常用
	int b = static_cast<int>(a);
	cout << "b = " << b << endl;

	int c = 8;
	const int *p = &c;
	//*p = 4;编译错误，指针指向的内存空间不能修改
	//int *p2 = p; //编译错误
	//2、const_cast 只能用于指针类型,去掉const属性
	int *p2 = const_cast<int*>(p);
	*p2 = 5;
	cout << "c = " << c << endl;

	//3、dynamic_cast 对象向下转型(继承关系)

	//4、reinterpret_cast 用于指针(转换指针的类型)
	char ch = 'd';
	char *p_ch = &ch;
	int * p_ch1 = reinterpret_cast<int*>(p_ch);
	cout << *p_ch1 << endl;
}

void main1()
{
	cast_type();
	system("pause");
}